package com.bto.leasetest.config.async;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;


@EnableAsync
@Configuration
public class AsyncConfig implements AsyncConfigurer {

    @Override
    public Executor getAsyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(10); // 设置核心线程数
        executor.setMaxPoolSize(100); // 设置最大线程数
        executor.setQueueCapacity(10); // 设置队列容量
        executor.setThreadNamePrefix("MyAsyncThread-"); // 设置线程名称前缀
        executor.setAwaitTerminationSeconds(60); // 设置延迟时间为60秒
        executor.initialize();
        return executor;
    }

}

